RAIS  3.2
C:/Projekte/RAIS/Specific Masks/ChangePassword.aspx.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Data;
00030 using System.Configuration;
00031 using System.Collections;
00032 using System.Web;
00033 using System.Web.Security;
00034 using System.Web.UI;
00035 using System.Web.UI.WebControls;
00036 using System.Web.UI.WebControls.WebParts;
00037 using System.Web.UI.HtmlControls;
00038 using System.Data.SqlClient;
00039 using System.Data.Sql;
00040 using System.Data.SqlTypes;
00041 
00042 using RAIS.Common.UserManagement;
00043 //using RAIS.ApplicationLogicLayer;
00044 
00045 namespace RAIS.UI.SpecificMasks
00046 {
00050     public partial class ChangePassword : System.Web.UI.Page
00051     {
00052         //*********************************************************************
00053         #region Properties
00054 
00057         protected UserData CurrentUser
00058         {
00059             get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00060         }
00061         #endregion
00062         #region Event handlers
00063         protected void Page_PreLoad(object sender, EventArgs e)
00064         {
00065             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00066         }
00073         protected void Page_Load(object sender, EventArgs e)
00074         {
00075                         this.Response.Cache.SetNoStore();
00076                         if (this.CurrentUser == null)
00077                 UI.Common.AccessManagement.SignOut(this);
00078 
00079             if (!this.IsPostBack)
00080             {
00081                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00082                 this.LBLerror.Text = "";
00083 
00084                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00085 //                              this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest);
00086                         }
00087         }
00094         protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00095         {
00096             UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00097         }
00098 
00105         protected void LBTNlogout_Click(object sender, EventArgs e)
00106         {
00107             UI.Common.AccessManagement.SignOut(this);
00108         }
00109         #endregion
00110 
00111         protected void BTNchangepassword_Click(object sender, EventArgs e)
00112         {
00113 
00114             {
00115                 string NewPasswordHashed = UserData.HashPassword(TXTnewpassword.Text);
00116                 string OldPasswordHashed = UserData.HashPassword(TXToldpassword.Text);
00117 
00118                 if (this.TXTnewpassword.Text == this.TXTconfirmnewpassword.Text)
00119                 {
00120                     if (this.TXTnewpassword.Text == "")
00121                     {
00122                         this.LBLerror.Text = "Password cannot be left empty";
00123                         this.LBLerror.ForeColor = System.Drawing.Color.Red;
00124                     }
00125                     else
00126                     {
00127                         ConnectionStringSettings connection =
00128                             ConfigurationManager.ConnectionStrings["RAISConnectionString"];
00129 
00130                         SqlConnection conn = new SqlConnection(connection.ConnectionString);
00131                         SqlCommand cmd = new SqlCommand("usp_UpdatePassword", conn);
00132                         cmd.CommandType = CommandType.StoredProcedure;
00133                         cmd.Parameters.AddWithValue("@UserName", LBLusernameNoTranslation.Text);
00134                         cmd.Parameters.AddWithValue("@Password", OldPasswordHashed);
00135                         cmd.Parameters.AddWithValue("@NewPassword", NewPasswordHashed);
00136 
00137                         try
00138                         {
00139                             conn.Open();
00140                             cmd.ExecuteNonQuery();
00141                             LBLerror.Text = "Password Sucessfully Changed";
00142                             this.LBLerror.ForeColor = System.Drawing.Color.Green;
00143                         }
00144                         catch
00145                         {
00146                             this.LBLerror.Text = "Your old password does not match our records";
00147                             this.LBLerror.ForeColor = System.Drawing.Color.Red;
00148                         }
00149                         finally
00150                         {
00151                             conn.Close();
00152                         }
00153                     }
00154                 }
00155                 else
00156                 {
00157                     this.LBLerror.Text = "Password mismatch";
00158                     this.LBLerror.ForeColor = System.Drawing.Color.Red;
00159                 }
00160             }
00161             #region Private helper methods
00162             #endregion
00163         }
00164     }
00165 }